<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui"
	xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:body>
	<ui:composition template="/template/base.xhtml">
		<ui:define name="content">
			<h:form id="tutoria-form">
				<p:growl id="growl" showDetail="true" sticky="true" />
				<p:spacer />

				<p:panel header="Detalle de tutorias">
					<p:dataTable id="dtTutoria" var="tutoria"
						value="#{tutoriaBean.tutorias}" rows="10" paginator="true"
						paginatorPosition="bottom"
						paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
						rowsPerPageTemplate="5,10,15"
						selection="#{tutoriaBean.tutoriaSelected}" rowKey="#{tutoria.id}"
						selectionMode="single" emptyMessage="No se registraron tutorias">

						<p:ajax event="rowSelect" listener="#{tutoriaBean.onRowSelect}" />

						<p:column headerText="ID">
							<h:outputText value="#{tutoria.id}" />
						</p:column>
						<p:column headerText="Materia">
							<h:outputText value="#{tutoria.materia.descripcion}" />
						</p:column>
						<p:column headerText="TipoPrecio">
							<h:outputText value="#{tutoria.tipoPrecio}" />
						</p:column>
						<p:column headerText="Precio">
							<h:outputText value="#{tutoria.precioTutoria}" />
						</p:column>
						<p:column headerText="Costo">
							<h:outputText value="#{tutoria.costoTutoria}" />
						</p:column>

						<f:facet name="footer">
							<p:commandButton process="dtTutoria" icon="ui-icon-document"
								value="Agregar" oncomplete="PF('dlgTutoriaAdd').show()" />
							<p:commandButton process="dtTutoria" icon="ui-icon-pencil"
								value="Editar" oncomplete="PF('dlgTutoriaEdit').show()"
								update=":form-edit:pnlGridTutoria"
								disabled="#{tutoriaBean.bloquearBotones}" />
							<p:commandButton process="dtTutoria" icon="ui-icon-trash"
								value="Borrar" actionListener="#{tutoriaBean.deleteTutoria}"
								update="dtTutoria" disabled="#{tutoriaBean.bloquearBotones}">
								<p:confirm header="Borrar Tutoria"
									message="Estas seguro que queres borrar?" icon="ui-icon-alert" />
							</p:commandButton>
						</f:facet>
					</p:dataTable>
				</p:panel>

				<p:confirmDialog global="true" showEffect="fade"
					hideEffect="explode">
					<p:commandButton value="Si" type="button"
						styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
					<p:commandButton value="No" type="button"
						styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
				</p:confirmDialog>
			</h:form>

			<p:dialog header="Agregar Tutoria" id="PdglTutoriaAdd"
				widgetVar="dlgTutoriaAdd" modal="true">
				
				<h:form id="form-add">
					<p:panelGrid columns="2" columnClasses="column"
						id="pnlGridAddTutoria">

						<p:outputLabel value="Materia" for="materia" />
						<p:selectOneMenu id="materia"
							value="#{tutoriaBean.materia.materiaSelected}"
							converter="materiaConverter">
							<c:forEach var="materia" items="#{materiaBean.materias}">
								<f:selectItem itemValue="#{materia}"
									itemLabel="#{materia.descripcion}" />
							</c:forEach>
						</p:selectOneMenu>

						<p:outputLabel value="TipoPrecio" for="tipoPrecio" />
						<p:inputText id="tipoPrecio" required="true"
							value="#{tutoriaBean.tipoPrecio}" />

						<p:outputLabel value="Precio" for="precio" />
						<p:inputText id="precio" required="true"
							value="#{tutoriaBean.precioTutoria}" />

						<p:outputLabel value="Costo" for="costo" />
						<p:inputText id="costo" value="#{tutoriaBean.costoTutoria}" />


						<p:commandButton process="pnlGridAddTutoria"
							icon="ui-icon-document" value="Agregar"
							action="#{tutoriaBean.saveTutoria()}"
              style="text-align:right; float:right"
              onclick="PdglTutoriaAdd.hide();" oncomplete=""
							update=":tutoria-form:dtTutoria,:tutoria-form:growl" />
					</p:panelGrid>

				</h:form>
			</p:dialog>

			<p:dialog header="Tutroria seleccionado" id="PdglTutoriaEdit"
				widgetVar="dlgTutoriaEdit" modal="true">
				<h:form id="form-edit">
					<p:panelGrid columns="2" columnClasses="column" id="pnlGridTutoria">

						<p:outputLabel value="Materia" for="materia" />
						<p:selectOneMenu id="materia"
							value="#{tutoriaBean.materia.materiaSelected}"
							converter="materiaConverter">
							<c:forEach var="materia" items="#{materiaBean.materias}">
								<f:selectItem itemValue="#{materia}"
									itemLabel="#{materia.descripcion}" />
							</c:forEach>
						</p:selectOneMenu>

						<p:outputLabel value="TipoPrecio" for="tipoPrecio" />
						<p:inputText id="tipoPrecio" required="true"
							value="#{tutoriaBean.tipoPrecio}" />

						<p:outputLabel value="Precio" for="precio" />
						<p:inputText id="precio" required="true"
							value="#{tutoriaBean.precioTutoria}" />

						<p:outputLabel value="Costo" for="costo" />
						<p:inputText id="costo" value="#{tutoriaBean.costoTutoria}" />

						<p:spacer />
						
						<p:commandButton process="pnlGridTutoria" value="Actualizar"
							action="#{tutoriaBean.editTutoria()}"
              style="text-align:right; float:right" onclick="PdglTutoriaEdit.hide()"
							update=":tutoria-form:dtTutoria,:tutoria-form:growl" />
							
					</p:panelGrid>
				</h:form>
			</p:dialog>

		</ui:define>
	</ui:composition>
</h:body>
</html>
